import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';

const baseUrl = '/afterSales/api/v1';
const resourceName = formatMessage({
    id: 'api.resourceName',
    defaultMessage: '索赔单据报表'
});

const getListDq = formatMessage({
    id: 'api.message.getList',
    defaultMessage: '查询大区数据'
});

const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询{resourceName}'
}, {resourceName});

const getPersonnelDesc = formatMessage({
    id: 'api.message.getPersonnelDesc',
    defaultMessage: '查询人员信息'
});

// 索赔单据报表(1)-不勾选同比(false)
export const getBillFalse = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/claimReportForms/billFalse?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};

// 索赔单据报表(1)-勾选同比(true)
export const getBillTrue = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/claimReportForms/billTrue?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};

// 单据审核报表(2)-不勾选同比(false)
export const getApproveFalse = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/claimReportForms/approveFalse?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};

// 单据审核报表(2)-勾选同比(true)
export const getApproveTrue = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/claimReportForms/approveTrue?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};

// 索赔单据量(3)-自动勾选环比(true)
export const getBillAmount = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/claimReportForms/billAmount?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};

// 通过率/一次通过率(4/5)-自动勾选环比(true)
export const getOnePassRate = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/claimReportForms/onePassRate?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};

// 拒赔/驳回(6/7)-不勾选环比(false)
export const getRejectFalse = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/claimReportForms/rejectFalse?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};

// 拒赔/驳回(6/7)-勾选环比(true)
export const getRejectTrue = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/claimReportForms/rejectTrue?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};

// 查询大区数据列表
export const getList = condition => {
    const queryString = stringify(condition);
    return request(`${baseUrl}/marketDepartments?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDq));
};

// 查询人员信息
export const getPersonnels = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/personnels/forDealerServiceInformation?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getPersonnelDesc));
};
